//
//  MZNewsDetailSelectableViewController.m
//  Mehfile Zainab
//
//  Created by Badourali Azad on 04/12/2013.
//  Copyright (c) 2013 Azad Badourali. All rights reserved.
//

#import "MZNewsDetailSelectableViewController.h"

@interface MZNewsDetailSelectableViewController ()

@end

@implementation MZNewsDetailSelectableViewController

@synthesize contentView;
@synthesize dateLabel;
@synthesize titleLabel;
@synthesize imageView;
@synthesize newsItem;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

    }
    return self;
}

- (UIColor *)colorFromHexString:(NSString *)hexString {
    unsigned rgbValue = 0;
    NSScanner *scanner = [NSScanner scannerWithString:hexString];
    [scanner setScanLocation:1]; // bypass '#' character
    [scanner scanHexInt:&rgbValue];
    return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    NSString *urlString = [newsItem getNewsImage];
    NSString *filePath = [FileManager getCachedDataFile:urlString];
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    UIImage *image = [UIImage imageWithData:data];
    self.imageView.image = [image scaleToSize:CGSizeMake(92.0f,88.0f)];
    
    self.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
	self.titleLabel.text = [newsItem getNewsTitle];
    self.titleLabel.textColor = [self colorFromHexString:@"#C22809"];
    self.titleLabel.font = [UIFont fontWithName:@"Futura-CondensedMedium" size:30.0f];

    self.dateLabel.text = [newsItem getNewsDate];
    
    self.contentView.editable = FALSE;
    self.contentView.dataDetectorTypes = UIDataDetectorTypeAddress | UIDataDetectorTypeLink | UIDataDetectorTypePhoneNumber; //UIDataDetectorTypeAll;
    self.contentView.text = [newsItem getNewsContent];
    self.contentView.textColor = [self colorFromHexString:@"#bcc2c8"];
    self.contentView.font = [UIFont fontWithName:@"Futura-CondensedMedium" size:24.0f];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
